<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/8
 * Time: 11:00
 *
 * 登入成功，则设置一个cookies,名字：Token,值md5(用户名+密码+时间戳),效期：24小时
 *
 */

$userInfo = [
    ['admin','888888'],
    ['chen','123456']
];

echo $_POST['userName'].'<br />';
echo $_POST['pwd'].'<br />';

$temporaryName = '';  //用于临时存放 $userInfo[$i][0]的值
$temporaryPwd = '';   //用于临时存放 $userInfo[0][$i]的值

if(!empty($_POST['userName']) && !empty($_POST['pwd'])){
    for($i=0;$i<count($userInfo);$i++){
        $temporaryName = $userInfo[$i][0];
        $temporaryPwd = $userInfo[$i][1];
        if($temporaryName==$_POST['userName'] && $temporaryPwd==$_POST['pwd']){
            echo '登录成功<br />';
            $cookieName = md5($_POST['userName'].$_POST['pwd'].time());
            echo $cookieName.'<br />';
            setcookie('Token',$cookieName,time()+24*3600);
            echo '<a href="userCenter.php">进入用户中心</a>';
            die();
        }
    }
    echo '用户名或密码不正确';
}else{
    echo '你的用户名或者密码为空';
}





